home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / gnuplotMode.tcl < prev    next >
Encoding:
Text File  |  1997-12-08  |  70.3 KB  |  2,526 lines  |  [TEXT/ALFA]

  1. #  
  2. # "gnuplotMode.tcl"  
  3. #                                    created: 26/4/97 {7:59:36 pm} 
  4. #                                last update: 8/12/97 {10:03:21 pm} 
  5. #  Author: Jeff Schindall
  6. #  E-mail: <mailto:schindall@nrl.navy.mil>
  7. #    mail: Naval Research Laboratory 
  8. #          Acoustics Division --- Code 7120
  9. #          4555 Overlook Ave SW
  10. #          Washington, DC, 20375 USA ]
  11. #    
  12. # gnuplotMode.tcl, Version 1.83       For  gnuplot 3.6
  13. #
  14. # This is a set of TCL proc's that allow the shareware Macintosh 
  15. # text editor Alpha to serve as a front end for GNUPLOT for 
  16. # Macintosh version 3.6. This script requires Alpha 7.0 or later.
  17. #
  18. # Just use 'shift-ctrl-g' to launch a gnuplot console
  19. # (Note: Vince updated this file for use with Alpha 7.0b4)
  20. #############################################################################
  21. #
  22. # Autoload procedures
  23. #
  24. #
  25. alpha::mode GPLT 1.8.1 dummyGPLT {*.gp *.gnu *.gnp *.gplt *.GP *.GNU *.GNP *.GPLT }  \
  26.         GnuplotMenu {
  27.     addMenu GnuplotMenu "•415"
  28.     set modeCreator(GPLT) GPLT
  29.     set modeCreator(GPSE) GPLT
  30.     # Set GLOBAL mode binding to bring up gnuplot Console
  31.     bind 'g' <sz> { GP_Console  }
  32.     bind 'n' <sc> { GP_NewWindow  }
  33. }
  34.  
  35. ########################################################################
  36. #
  37. #  This mode was written by Jeff Schindall.  Some code was pinched from 
  38. #  other TCL files distributed with Alpha and matlab.tcl.
  39. #   
  40. #  Comments, suggestions, and bug reports should be sent to Jeff at
  41. #     mailto:schindall@nrl.navy.mil
  42. #
  43. #  You should be able to find the most recent current version of this
  44. #  gnuplotMode.tcl and the server app script at 
  45. #      
  46. #      ftp://ftp.ee.gatech.edu/pub/mac/gnuplot
  47. #
  48. #   and the most recent bleeding edge version at 
  49. #
  50. #      ftp://wave1m.nrl.navy.mil/pub/gnuplotMode.tcl.gz
  51. #
  52. #######################################################################
  53. #                                                                        
  54. #     Version History:                                                
  55. #                                                                        
  56. #         1.6    12/23/96                                                   
  57. #         -----------------------------------------------
  58. #         Floating palatte now very usefull.  User can run a script
  59. #         by selecting a script menu item, or edit the script by
  60. #         selecting the script menu item with the option key held down
  61. #
  62. #         1.5.9b    12/10/96                                                   
  63. #         -----------------------------------------------
  64. #         repaired broken scripts menu
  65. #         added a "edit scripts" menu----eventually, this one
  66. #         will go away, but the functionality will be retained
  67. #
  68. #         1.5.9    12/05/96                                                   
  69. #         -----------------------------------------------
  70. #         repaired broken pwd display
  71. #
  72. #         1.5.8    12/05/96                                                   
  73. #         -----------------------------------------------
  74. #         plot '-' now works
  75. #         pause in demo-mode works better
  76. #         added option to rebuild scripts menu
  77. #
  78. #         1.5.7    11/13/96                                                   
  79. #         -----------------------------------------------
  80. #         Check OUTP event for "Sorry, " string
  81. #         so that help for unknown item will be sent to console
  82. #         rather than a new output terminal page
  83. #
  84. #         1.5.6    11/07/96                                                   
  85. #         -----------------------------------------------
  86. #          Fixed a few floating menu buggers
  87. #
  88. #         1.5.5    11/06/96                                                   
  89. #         -----------------------------------------------
  90. #          Added a "Scripts" menu which auto loads any script
  91. #         in gnuplots "Scripts" folder (or subfolder)
  92. #         Made terminal output window creation faster
  93. #                                                                        
  94. #         1.5.4    11/05/96                                                   
  95. #         -----------------------------------------------
  96. #          Added terminal output windows for PS/TeX/MIF/etc.
  97. #                                                                        
  98. #         1.5.3    11/02/96                                                   
  99. #         -----------------------------------------------
  100. #          See 1.5.2
  101. #                                                                        
  102. #         1.5.2    11/02/96                                                   
  103. #         -----------------------------------------------
  104. #          Attempt to fix ome context switching weirdness
  105. #                                                                        
  106. #         1.5.1    10/23/96                                                   
  107. #         -----------------------------------------------
  108. #          Added some more apple event and floating palatte 
  109. #           options.
  110. #
  111. #         1.5    10/22/96                                                   
  112. #         -----------------------------------------------
  113. #          Slight bug fixes
  114. #
  115. #         1.5b3    07/18/96                                                   
  116. #         -----------------------------------------------
  117. #          Now works with Alpha 6.1 and higher.
  118. #         Added Floating menu...
  119. #
  120. #         1.5b2    07/16/96                                                   
  121. #         -----------------------------------------------
  122. #          Now works with Alpha 6.1 and higher.
  123. #
  124. #         1.5b1    07/02/96                                                   
  125. #         -----------------------------------------------
  126. #          Modify code so that it is compliant with the new
  127. #            mode conventions Pete added to 6.2 (see changes file).
  128. #         This script should still work for Alpha pre 6.2!
  129. #          Nifty self-installer!
  130. #                                                                          
  131. #                                                                          
  132. #         1.4.4    04/26/96                                                   
  133. #         -----------------------------------------------
  134. #          Modify trap for broken eventhandler on 68k                 
  135. #              so that pause works correctly and so that        
  136. #              gnuplot can bring itself to the front            
  137. #                                                                          
  138. #                                                                          
  139. #         1.4.3    04/24/96                                                  
  140. #         -----------------------------------------------
  141. #          Add trap for broken eventhandler on 68k                     
  142. #                                                                          
  143. #         1.4.2    04/17/96                                                
  144. #         -----------------------------------------------
  145. #          Let alpha do bookkeeping on globals                         
  146. #                                                                          
  147. #         1.4.1    04/15/96                                                       
  148. #         -----------------------------------------------
  149. #          Repaired broken quit and switchto menu options         
  150. #                                                                          
  151. #                                                                          
  152. #         1.4.0    04/14/96                                                       
  153. #         -----------------------------------------------
  154. #          GPLT mode preferences accessable from                  
  155. #            config:currentmode:flags... menu            
  156. #          Keyword coloring now works and is auto-sourced
  157. #            whenever GPTLPrefs.tcl is closed                          
  158. #          Reorganized and added to gnuplot menu            
  159. #          Reorganized all mode specifice procedures and 
  160. #             variable names                                        
  161. #                                                                          
  162. #                                                                          
  163. #         1.3.9    04/10/96                                                       
  164. #         -----------------------------------------------
  165. #          Keyword coloring editable from gnuplot pref menu.        
  166. #          gnuplot pref menu re-arranged                                  
  167. #          this package should display the path                       
  168. #             on the message bar                                              
  169. #                                                                          
  170. #                                                                          
  171. #         1.3.8    03/13/96                                                       
  172. #         -----------------------------------------------
  173. #          Re-arranged some code.                                  
  174. #                                                                                   
  175. #                                                                          
  176. #         1.3.7    03/13/96                                                       
  177. #         -----------------------------------------------
  178. #          Added support for cwd display on message bar    
  179. #                                                                                   
  180. #                                                                          
  181. #         1.3.6    02/26/96                                                       
  182. #         -----------------------------------------------
  183. #          Added graph button preference and repaired        
  184. #        my broken closeHook procedure                         
  185. #                                                                          
  186. #         1.3.5    02/01/96                                                       
  187. #         -----------------------------------------------
  188. #          Some minor fixes to console routines                
  189. #                                                                          
  190. #                                                                        
  191. #         1.3.4    02/01/96                                                       
  192. #         -----------------------------------------------
  193. #       Added "iconic" graph window which switches to             
  194. #               the gnuplot application                            
  195. #          Added a "gnuplot prefs" submenu                    
  196. #                                                                        
  197. #         1.3.3    12/20/95                                                       
  198. #         -----------------------------------------------
  199. #       Added Live History window                                       
  200. #          Added a function sub-menu                            
  201. #                                                                         
  202. #                                                                        
  203. #         1.3.2    12/15/95                                                       
  204. #         -----------------------------------------------
  205. #       History dump Really working this time.......           
  206. #          Included a kludge eventHander: GPIC EXEC        
  207. #             for Dave (temporary)                                
  208. #                                                                        
  209. #         1.3.1    12/14/95                                                       
  210. #         -----------------------------------------------
  211. #          Consolidated console and script editor modes.    
  212. #          Supports server once again.                           
  213. #       History dump working.......                            
  214. #                                                                        
  215. #                                                                        
  216. #         1.3    12/09/95                                                           
  217. #         -----------------------------------------------
  218. #          Should work with gnuplot app and              
  219. #          Fixed an "unknown" bug---thanks Vince            
  220. #          Files with gnuplot creator open in gnuplot mode
  221. #          Added several eventHandler's to work with the          
  222. #         gnuplot's new personality module                     
  223. #       NOTE:  No longer supports the gnuplot server app,      
  224. #              but I might add it back in later...             
  225. #                                                                        
  226. #         1.2.5    8/29/95                                            
  227. #         -----------------------------------------------
  228. #           File type as well as creator settings in place
  229. #                                                                        
  230. #                                                                        
  231. #         1.2.4    8/28/95                                            
  232. #         -----------------------------------------------
  233. #            I honestly don't recall                                
  234. #                                                                        
  235. #         1.2.3    8/27/95                                            
  236. #         -----------------------------------------------
  237. #           Fixed a few prompt related items.                
  238. #            I need to clean up the code a bit                
  239. #            especially in the console output routines        
  240. #                                                                        
  241. #         1.2.2    8/23/95                                            
  242. #         -----------------------------------------------
  243. #           Repaired help/prompting/etc which broke in    
  244. #                1.2.1                                                    
  245. #            DoSelection works for multiple lines            
  246. #                                                                        
  247. #                                                                        
  248. #         1.2.1    8/23/95                                            
  249. #         -----------------------------------------------
  250. #           Now works with unthreaded 68k systems                       
  251. #                                                                        
  252. #                                                                        
  253. #         1.2    8/23/95                                                
  254. #         -----------------------------------------------
  255. #           Deal w/"pause -1"     properly                                   
  256. #            cmd-dbl-click now works for all prompts         
  257. #            Cleaned up set output creator                        
  258. #                                                                          
  259. #                                                                        
  260. #         1.1    8/22/95                                                
  261. #         -----------------------------------------------
  262. #           Set output creators from gnuplot menu            
  263. #            Quit Working properly once again                    
  264. #            Added ERRP eventHandler for those w/o the             
  265. #          Thread Manager                                        
  266. #                                                                        
  267. #         1.0    8/21/95  (these release numbers are backwards)        
  268. #         -----------------------------------------------
  269. #           First working release                                 
  270. #                                                                        
  271. #    ============= Below were really beta's ==================== 
  272. #                                                                        
  273. #         1.0.6    8/17/95                                            
  274. #         -----------------------------------------------
  275. #           Cleaned up several procs                            
  276. #            Quit now works properly                                
  277. #                                                                        
  278. #                                                                        
  279. #         1.0.5    8/16/95                                            
  280. #         -----------------------------------------------
  281. #             replaced 'dosc' w/AEBuild                            
  282. #             added eventHandler  (thanks Dave)                    
  283. #             dumped "clean" window since Pete will            
  284. #                add this functionality to "new" in 6.0.2    
  285. #                                                                        
  286. #                                                                        
  287. #         1.0.4    8/12/95                                            
  288. #         -----------------------------------------------
  289. #             new modeVar to keep console "clean"             
  290. #                                                                        
  291. #                                                                        
  292. #         1.0.3    8/12/95                                            
  293. #         -----------------------------------------------
  294. #             Fixed bugs in closing console window            
  295. #             Added wristwatch cursor while waiting for gnuplot        
  296. #                                                                        
  297. #         1.0.2    8/11/95                                            
  298. #         -----------------------------------------------
  299. #         When console window is closed the gnuplot    
  300. #              app is quit and user is prompted to save    
  301. #          the Alpha/gnuplot history                        
  302. #                                                                        
  303. #         Command-Dbl-Click anywhere between gnuplot     
  304. #              prompts to select gnuplot output.  Nice        
  305. #          if you send term output to the console.        
  306. #                                                                        
  307. #         1.0.1    8/8/95                                            
  308. #         -----------------------------------------------
  309. #            Handles multiplot mode                                
  310. #             set output file CREATOR modeVar    (not yet)    
  311. #                                                                         
  312. #                                                                        
  313. #         1.0    8/7/95                                                
  314. #         -----------------------------------------------
  315. #            Now works with 3.6 (but not with 3.5)            
  316. #                                                                         
  317. #    =======================================================        
  318. #                                                                         
  319. #         0.4    8/3/95                                                
  320. #         -----------------------------------------------
  321. #           user specified colorizing through check pop-up       
  322. #             menu in GNUc console.  You must quit alpha and       
  323. #             restart to see the effects.  Also, you must          
  324. #         make sure that keywords and colors don't overlap.    # 
  325. #                                                              
  326. #                                                                        
  327. #         0.3    8/3/95                                                
  328. #         -----------------------------------------------
  329. #             Console position remembered between sessions
  330. #                                                                        
  331. #              Enabled command history to be dumped to a window        
  332. #                                                                  
  333. #                                                                        
  334. #         0.2    8/2/95                                                
  335. #         -----------------------------------------------
  336. #             Added a    Switch to gnuplot    menu option            
  337. #                                                                        
  338. #             Added Console modeVar                                        
  339. #                                                                        
  340. #         Added run in background modeVar                           
  341. #                                                                        
  342. #             Command History mostly working in console.    
  343. #                                                                        
  344. #             Cleaned    things up a    bit.                            
  345. #                                                                        
  346. #                                                                        
  347. #         0.1    8/1/95                                                
  348. #         -----------------------------------------------
  349. #             converted matlab.tcl to gnuplot.tcl            
  350. #                                                                        
  351. #                                                                        
  352. ###############################################################
  353.  
  354.  
  355.  
  356. proc dummyGPLT  {} {}
  357. proc GnuplotMenu {} {}
  358. hook::register mode::init GP_GraphButton GPLT
  359. hook::register mode::editPrefsFile GP_editCurrentModePrefs GPLT
  360. hook::register dialog::modifyModeFlags GP_modifyModeFlags GPLT        
  361. hook::register closeHook GP_CloseHook GPLT
  362. hook::register deactivateHook GP_DeactivateHook GPLT
  363. hook::register activateHook GP_ActivateHook GPLT
  364.  
  365. newPref f elecRBrace {0} GPLT
  366. newPref v prefixString {# } GPLT
  367. newPref f electricSemi {0} GPLT
  368. newPref v wordBreak {[a-zA-Z0-9_]+} GPLT
  369. newPref f elecLBrace {0} GPLT
  370. newPref f wordWrap {0} GPLT
  371. newPref v wordBreakPreface {[^a-zA-Z0-9_]} GPLT
  372. newPref v tabSize {3} GPLT
  373. newPref v prefixString {# } GPLT
  374. newPref f NevrSavHist {0} GPLT
  375. newPref f LiveHist {1} GPLT
  376. newPref f GraphButton {1} GPLT
  377. newPref f EventHandler {1} GPLT
  378. newPref v bracesColor blue GPLT
  379. newPref v bracesColor blue GPLT
  380. newPref v stringColor green GPLT
  381. newPref v commentColor red GPLT
  382. set gpTermCt 0
  383.  
  384. ###BGK
  385.    # (DO NOT ERASE Previous line)
  386.    # 
  387.    # NOTE:  Some coloring is controlled via 
  388.    #        Config:current mode:flags... menu
  389.    #
  390.  
  391.       ### BLUE words ###
  392.  
  393. set gpBlueWords { 
  394.     console  set show plot splot \\
  395.     autoscale      binary         boxxyerrorbars bugs
  396.     call           cd             clear          co-ordinates
  397.     comments             environment    exit
  398.     expressions    fit                       if
  399.     introduction   line-editing   load           pause
  400.     plot           print          pwd            quit
  401.     replot         reread         reset          save
  402.     seeking-assistance set            shell          show
  403.     splot          startup        style          substitution
  404.     test           update         userdefined    xyerrorbars
  405.     xerrorbars yerrorbars
  406.     "Copyright(C) 1986 - 1995" "Copyright(C) 1986 - 1996"
  407.  
  408.  
  409.  
  410.       ### RED words ###
  411.  
  412. set gpRedWords { 
  413.     topics available: Subtopics available  
  414.     server macintosh Press return for more: Help topic: 
  415.     Subtopic of {G N U P L O T} {(pre 3.6)}  3.5 3.6 
  416.     version for 68k ppc Power Macintosh patchlevel 
  417.     last modified first second
  418.  
  419.  
  420.      ### GREEN WORDS ###
  421.  
  422. set gpGreenWords {  
  423.     ranges         smooth         data-file      datafile          
  424.     parametric     locale         nosquare       errorbars
  425.     gnuplot        gnuplot>       term           square         
  426.     angles         arrow          autoscale      bar
  427.     bmargin        border         boxwidth       clabel
  428.     clip           cntrparam      contour        data
  429.     dgrid3d        dummy          encoding       format
  430.     function       grid           hidden3d       isosamples
  431.     key            keytitle       label          lmargin
  432.     logscale       mapping        margin         missing
  433.     multiplot      mx2tics        mxtics         my2tics
  434.     mytics         mztics         noarrow        noautoscale
  435.     noborder       noclabel       noclip         nodgrid3d
  436.     nokey          nolabel        nologscale     nomultiplot
  437.     nomx2tics      nomxtics       nomy2tics      nomytics
  438.     nomztics       noparametric   nopolar        nosurface
  439.     nox2dtics      nox2mtics      nox2tics       nox2zeroaxis
  440.     noxdtics       noxmtics       noxtics        noxzeroaxis
  441.     noy2dtics      noy2mtics      noy2tics       noy2zeroaxis
  442.     noydtics       noymtics       noytics        noyzeroaxis
  443.     nozdtics       nozeroaxis     nozmtics       noztics
  444.     offsets        origin         output         parametric
  445.     pointsize      polar          punctuation    rmargin
  446.     rrange         samples        size           specify
  447.     style          surface        syntax         terminal
  448.     tics           ticscale       ticslevel      time
  449.     timefmt        title          tmargin        trange
  450.     urange         view           vrange         x2dtics
  451.     x2label        x2mtics        x2range        x2tics
  452.     x2zeroaxis     xdata          xdtics         xlabel
  453.     xmtics         xrange         xtics          xzeroaxis
  454.     y2dtics        y2label        y2mtics        y2range
  455.     y2tics         y2zeroaxis     ydtics         ylabel
  456.     ymtics         yrange         ytics          yzeroaxis
  457.     zdtics         zero           zeroaxis       zlabel
  458.     zmtics         zrange         ztics
  459.     threaded  
  460.  
  461.  
  462.  
  463.     ### MAGENTA WORDS ###
  464.  
  465. set gpMageWords  { 
  466.     with lines using  points  multiplot> mac gx eps enh
  467.     info-gnuplot dartmouth edu bug-gnuplot { \@ }
  468.     Send comments and requests for help to
  469.     Send bugs, suggestions and mods to
  470.                    
  471.  
  472.  
  473.     ### CYAN WORDS ###
  474.  
  475. set gpCyanWords  {   post mac     macintosh      texdraw
  476.     aifm           atari          dumb           enhpost
  477.     epson          epson180       epson60        fig
  478.     gpic           hpljii         imagen         iris4d
  479.     latex          linux          mf             mif
  480.     mtos           nec-cp6        pbm            pcl5
  481.     postscript     pslatex        regis          starc
  482.     table          tandy60        tgif           uniplex
  483.     vdi            windows        unknown        pstricks
  484.     png            dxf            cgm            gif
  485.     emtex          pstex          eepic          tpic
  486.     pstricks       texdraw
  487.     Thomas Williams, Colin Kelley and many others 
  488.     Russell Lang, Dave Kotz, John Campbell. Gershon Elber
  489.  
  490. #
  491. # Color keywords for GPLT mode
  492. #
  493. regModeKeywords  -i "\}" -i "\{"  -i ">" -i "<" -i ")" -i "("  -i "/" -i "\\"  \
  494.     -i "\]" -i "\[" -i "\$" -i "\'" -i "\`" -i ">" -i "<" -i "^" -i "_" \
  495.     -I $GPLTmodeVars(bracesColor) \
  496.      -e {#} -c $GPLTmodeVars(commentColor) \
  497.     -s $GPLTmodeVars(stringColor)  \
  498.     -k red GPLT $gpRedWords
  499. regModeKeywords -a -k blue GPLT $gpBlueWords
  500. regModeKeywords -a -k green GPLT $gpGreenWords
  501. regModeKeywords -a -k magenta GPLT $gpMageWords
  502. regModeKeywords -a -k cyan GPLT $gpCyanWords
  503.  
  504. #  (DO NOT ERASE NEXT TWO LINES)
  505. ###EGK
  506.  
  507.  
  508.  
  509. #define saved globals
  510. ensureset GnuplotSig                  {GPLT}  
  511. ensureset gp_CREA                  {ALFA}  
  512. ensureset gp_TYPE                  {TEXT}  
  513. ensureset gp_CreatorList [list] 
  514. ensureset gp_TypeList [list] 
  515. ensureset gp_CreatorNames [list] 
  516. ensureset gp_GEOM [list]
  517. ensureset gp_HistGEOM [list ]
  518. ensureset headerSuffices {$GPLTmodeSuffixes}
  519. ensureset sourceSuffices {$GPLTmodeSuffixes}
  520.  
  521. if {[llength $gp_CreatorList] == 0 \
  522.  || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  523.  || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  524.     set gp_CreatorList [list ALFA GPLT]
  525.     set gp_TypeList [list  TEXT TEXT]
  526.     set gp_CreatorNames [list  alpha gnuplot]
  527.     set gp_CREA {ALFA} 
  528.     set gp_TYPE {TEXT}
  529. }
  530.  
  531. #remove unused, previously saved globals
  532. if { [info exists GPLTmodeVars(FSIG)]}  { removeArrDef  GPLTmodeVars FSIG
  533.                                                         unset GPLTmodeVars(FSIG)
  534.                                                      } 
  535. if { [info exists GPLTmodeVars(CREA)]}  { removeArrDef  GPLTmodeVars  CREA
  536.                                                         unset GPLTmodeVars(CREA)
  537.                                                      } 
  538. if { [info exists GPLTmodeVars(TYPE)]}  { removeArrDef  GPLTmodeVars TYPE
  539.                                                         unset GPLTmodeVars(TYPE)
  540.                                                      } 
  541.  
  542.  
  543. #############################################################################
  544. #
  545. #  global variables
  546. #
  547.  
  548. set gp_CommandHist [list]
  549. set gp_CommandNum 0
  550.  
  551. set gp_Prompt       "gnuplot> "
  552. set gp_MultiPrompt  "multiplot> "
  553. set gp_ContPrompt   "> "
  554. set gp_HelpPrompt   ": "
  555.  
  556. set gp_Prompts [list $gp_Prompt $gp_ContPrompt $gp_MultiPrompt ]
  557.  
  558. set gp_Console  "  gnuplot  "
  559. set gp_Hist     "  history  "
  560. set gp_Graph     "  graph  "
  561. set gp_sl [list]
  562.  
  563. #############################################################################
  564. #
  565. #  Bind some keys
  566. #
  567.  
  568. # Editing .gnu files
  569.  
  570. bind '\r' <z>  GP_DoLine             "GPLT"
  571.  
  572. # Command Window
  573.  
  574. bind '\r'      GP_CarriageReturn     "GPLT"
  575. bind up        GP_PrevCommand        "GPLT"
  576. bind down      GP_NextCommand        "GPLT"
  577. bind '1'  <c>  GP_Console            "GPLT"
  578. bind '2'  <c>  GP_Activate           "GPLT"
  579. bind '3'  <c>  GP_DumpHistory        "GPLT"
  580. bind 'f'  <sc>  GP_SaveAndExecute    "GPLT"
  581.  
  582.  
  583. # Repeat menu keys for command window
  584.  
  585. set gp_Launched {0}
  586.  
  587.  
  588.  
  589.  
  590. #############################################################################
  591. #
  592. #  gnuplot Menu stuff
  593. #
  594.  
  595.  menu -n    $GnuplotMenu -p GnuplotMenuItem    {                         
  596.      "/1console"                                                     
  597.      "/2graph"                                                     
  598.      "/3history"                                                     
  599.     "(-"    
  600.      "setWorkingFolder..."
  601.      "/P<UchoosePlotFile..."
  602.       "/L<Uload..."                                         
  603.      {menu -n "saveSettings" -p GnuplotMenuItem  {
  604.                   "/S<Uall"                  
  605.                  "(-"
  606.                  "setCmds" 
  607.                  "functions"         
  608.                 "variables"    
  609.             }
  610.      }
  611.      "(-"                                                                                                                                  
  612.      "/N<UnewScriptWin"                                                 
  613.       "/F<UsaveAndExecute"                                         
  614.     "(-"    
  615.      {menu  -s -m -n mathFunctions -p GnuplotMenuItem  {
  616.          {menu  -s -m -n Trigonometric -p GnuplotMenuItem  {
  617.         "cos"
  618.         "tan"
  619.         "sin"
  620.          }}
  621.          {menu  -s -m -n InverseTrig -p GnuplotMenuItem  {
  622.          "acos"
  623.          "asin"
  624.         "atan"         
  625.         }}
  626.          {menu  -s -m -n Hyperbolic -p GnuplotMenuItem  {
  627.         "cosh"
  628.         "sinh"
  629.         "tanh"
  630.         }}
  631.          {menu  -s -m -n special -p GnuplotMenuItem  {
  632.         "erf"            
  633.         "erfc"           
  634.         "inverf"                                  
  635.         "(-"
  636.         "gamma"                                       
  637.         "igamma"                        
  638.         "lgamma"                                      
  639.         "(-"
  640.         "ibeta"                                        
  641.          }}
  642.          {menu  -s -m -n bessel -p GnuplotMenuItem  {
  643.         "besj0"
  644.         "besj1"
  645.         "besy0"
  646.         "besy1"         
  647.         }}
  648.         "(-"
  649.         "abs"  
  650.         "arg"               
  651.         "sgn"     
  652.         "sqrt"
  653.         "(-"
  654.         "exp"
  655.         "log"
  656.         "log10"                                  
  657.         "(-"
  658.         "ceil"           
  659.         "floor" 
  660.         "rand"
  661.         "norm"
  662.         "invnorm"
  663.         "(-"
  664.         "real" 
  665.         "imag"
  666.         "int"
  667.             }
  668.         }
  669.      "(-"    
  670.      "/M<UdoSelection"                                             
  671.      "doLine"                                                         
  672.      "(-"
  673.      {menu -n gnuplotOptions -p GnuplotMenuItem     {         
  674.         "setPointSize..."
  675.          "(-"    
  676.         "/H<UclearHistory"
  677.          "(-"    
  678.           {menu -n setOutputCreator -p GnuplotMenuItem     {         
  679.             "select..."                                                 
  680.             "add..."                                                     
  681.              "delete..."                                                 
  682.             }                                                                 
  683.         }    
  684.         "keywordColoring..."                
  685.          }
  686.     }                
  687.     "readme..."
  688.      "/2switchTo gnuplot"                                         
  689.      "/Q<Uquit gnuplot"                                             
  690.  }                                                                         
  691.                                                                              
  692.  
  693.      # Attempt to overload the following command keys:
  694.      #
  695.        #  Command-1  :  Console
  696.         #  Command-2  :  Graph
  697.         #  Command-3  :  History
  698.                         
  699.                         
  700.                         
  701.  proc    GnuplotMenuItem {menu item} {                                 
  702.  #global GnuplotMenu                                                     
  703.      switch $item {                                                 
  704.             "console"                GP_Console                     
  705.             "graph"                     GP_Activate                     
  706.             "gnuplot"                     GP_Activate                     
  707.             "history"                GP_DumpHistory                     
  708.             "newScriptWin"            GP_NewWindow         
  709.             "choosePlotFile..."        GP_ChoosePlotFile         
  710.             "saveAndExecute"         GP_SaveAndExecute         
  711.             "load..."                 GP_LoadScript             
  712.             "all"                     { GP_SaveSettings "" }             
  713.             "setCmds"                 { GP_SaveSettings "set" }             
  714.             "functions"                 { GP_SaveSettings "fun" }             
  715.             "variables"                 { GP_SaveSettings "var" }             
  716.             "doSelection"             GP_DoSelection             
  717.             "doLine"                    GP_DoLine                          
  718.             "switchTognuplot"        GP_Activate                 
  719.             "select..."                 GP_SelectCreator         
  720.             "add..."                     GP_AddCreator             
  721.             "delete..."                 GP_DeleteCreator         
  722.             "clearHistory"            GP_ClearHistory             
  723.             "quitgnuplot"             GP_Quit                     
  724.             "keywordColoring..."        editCurrentModePrefs
  725.             "setWorkingFolder..."   GP_SetCWD
  726.             "setPointSize..."       GP_SetPTSZ
  727.             "readme..."                 GP_Readme
  728.             "labels..."                { GP_Dialog "labl" }
  729.             "line styles..."            { GP_Dialog "line" }
  730.             "text format..."            { GP_Dialog "text" }
  731.              "labels..."                { GP_Dialog "labl" }
  732.              "gxText"                { GP_Dialog "gxtx" }
  733.              "offsets..."             { GP_Dialog "oset" }
  734.             default                    { insertText [string tolower $item ] () 
  735.                                           backwardChar    
  736.                                      }
  737.             }                                                                 
  738.  }                                                                         
  739.                                                                              
  740. #############################################################################
  741. #
  742. #  setup the event handler for Alpha/gnuplot interapp communication
  743. #  This file only works with Alpha 7.0 or newer so we assume
  744. #  eventHandling actually works.
  745. #
  746.  
  747. if { 1 } {
  748.    # Setup event Handler for STDOUT
  749.       eventHandler GPSE OUTP "GP_STDOUThandler"  
  750.     
  751.     # Setup event Handler for systems w/o ThreadManager
  752.       eventHandler GPSE ERRP "GP_STDERRhandler"
  753.     
  754.     # *ICInitializeCommand // This initializes the console.  
  755.     # Alpha eventhandler is needed.
  756.     # 'GPIC init'
  757.      eventHandler GPIC init "GP_ConsoleH"
  758.     # 
  759.     # *ICInitializePath // sends the working directory as 
  760.    # stored in preferences.
  761.     # Since you aren't displaying the working directory anywhere, 
  762.    # we can ignore
  763.     # this for now.
  764.     # 'GPIC path', contains a string in the direct object.
  765.      eventHandler GPIC path "GP_SendPath"
  766.     # 
  767.     # ICExecute // Tells the console to execute a gnuplot command.  
  768.    # I can't think
  769.     # of a reason for this one in Alpha.  The menuing system uses 
  770.    # this one in the current console.  We could define an event however.
  771.     # 
  772.     # 
  773.     # ICInsertCommand // Might be slick.  An example of what this 
  774.    # does is where
  775.     # functions get pasted into the command line.  Not absolutely necessary
  776.     # though.
  777.    # 'GPIC' 'inse'
  778.     eventHandler GPIC inse "GP_INSEhandler"
  779.     # 
  780.     # ICComeToFront  // The function will bring Alpha to the front.  
  781.    # No handler needed.
  782.     # 
  783.     # *ICBringGnuplotToFront // Handler needed.  When you get this one, bring
  784.     # gnuplot to the front.
  785.     # 'GPIC tofr'
  786.      eventHandler GPIC tofr "GP_ActivateH"
  787.     # 
  788.     # *ICHandleAEReply // You'll get this one if somebody used a 
  789.    # gnuplot menu to
  790.     # do something which necessitated a reply from gnuplot. The 
  791.    # gnuplot interface
  792.     # will pass the reply to you for display.
  793.     # 'GPIC repl', handle this one just like the reply from your exec event.
  794.      eventHandler GPIC repl "GP_STDERRhandler"
  795.     # 
  796.     # *ICMakeNewDocument  // It sounds like this one is working already.
  797.     # 'core crel'
  798.      eventHandler core crel "GP_NewWindowH"
  799.     # 
  800.     # *ICOpenDocument // Alpha already knows about this one.
  801.     # --already defined in alpha---
  802.  
  803.     # The event 'GPIC' 'cbye' is now sent whenever gnuplot quits.
  804.    # This will let you close the console if somebody quits 
  805.    # gnuplot some other way. You could
  806.     # use this to eliminate your 'quit' trapping if you want.
  807.      eventHandler GPIC cbye "GP_CloseH"
  808.     # I also defined a new event: 'GPIC' 'EXEC'.  All you need to 
  809.    # do is take the
  810.     # data and send it back to gnuplot as a 'GPSE' 'exec' event. 
  811.    # This is a kludge
  812.     # to make the commands in the gnuplot app menus work. 
  813.    # It will eventually go away.
  814.      eventHandler GPIC EXEC "GP_Kludge"
  815.     
  816.     proc GP_Kludge {it} {
  817.        set outit  [GP_filtercurlyq $it]
  818.       GP_STDERR $outit
  819.       if { $it == "Unable to find process" } GP_Quit
  820.       return 0
  821.      }    
  822.      
  823.     proc GP_STDERRhandler {it} {
  824.         global gp_cwd
  825.         set outit  [GP_filtercurlyq $it]
  826.         GP_ExtractPath $it
  827.         GP_Results $outit
  828.         if { $it == "Unable to find process" } GP_Quit
  829.        return 0
  830.     }
  831.     
  832.     proc GP_STDOUThandler {it} {
  833.         global gp_cwd gp_Out gpTermCt
  834.         global win::Modes gp_Console gp_Graph win::Modes 
  835.         global GPLTmodeVars gp_Launched gp_GEOM
  836.         global gp_Prompt  gp_cwd GnuplotMenu 
  837.     
  838.         set outit  [GP_filtercurlyq $it]
  839.         GP_ExtractPath $it
  840.         set wins [winNames]    
  841.         
  842.         set itLen [ string length "$it" ]
  843.         set termID [ string range "$outit" 0 20 ]
  844.         set termType [ string range "$it" [expr $itLen -25] [expr $itLen -1] ] 
  845.         
  846.         if { [ string first "Sorry," "$termID" ] == 0 } {
  847.             insertText -w  $gp_Console "\n$outit"
  848.             return
  849.             
  850.         } elseif { [ string first "% GNUPLOT: LaTeX" "$termID" ] == 0 } {           
  851.             incr gpTermCt 1
  852. #            set gp_Out [getline "Enter name of output console?" "* TeX output $gpTermCt *" ]
  853.             set gp_Out "* TeX output $gpTermCt *"
  854.             set theMode "TeX"
  855.             
  856.         } elseif { [string first "%!PS-Adobe" "$termID" ] == 0 } {
  857.             incr gpTermCt 1
  858. #            set gp_Out [getline "Enter name of output console?" "* PS output $gpTermCt *" ]
  859.             set gp_Out "* PS output $gpTermCt *"
  860.             set theMode "PS"
  861.             
  862.         } elseif { [string first "<MIFFile 3.00>" "$termID" ] == 0 } {
  863.             incr gpTermCt 1
  864. #            set gp_Out [getline "Enter name of output console?" "* MIF output $gpTermCt *" ]
  865.             set gp_Out "* MIF output $gpTermCt *"
  866.             set theMode "PS"
  867.             
  868.         } elseif { [string first "% GNUPLOT: dxf" "$termID" ] >= 0 } {
  869.             incr gpTermCt 1
  870. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  871.             set gp_Out "* misc output $gpTermCt *"
  872.             set theMode "TEXT"
  873.             
  874.         } elseif { [string first "if unknown cmbase" "$termID" ] == 0 } {
  875.             incr gpTermCt 1
  876. #            set gp_Out [getline "Enter name of output console?" "* MF output $gpTermCt *" ]
  877.             set gp_Out "* MF output $gpTermCt *"
  878.             set theMode "TeX"
  879.             
  880.         } elseif { [string first "#Curve" "$termID" ] == 0 } {
  881.             incr gpTermCt 1
  882. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  883.             set gp_Out"* misc output $gpTermCt *"
  884.             set theMode "TEXT"
  885.             
  886.         } elseif { [ string index "$termID" 0  ] == " " && [ string first "TERM:“dumb”" "$termType" ] > 0 } {
  887.             set ns "\n"
  888.             append ns $outit
  889.             set outit "$ns"
  890.             set gp_Out $gp_Console
  891.             #set theMode "TEXT"
  892.  
  893.         } elseif { ![info exists gp_Out ] || [lsearch $wins $gp_Out ] < 0 } {
  894.             incr gpTermCt 1
  895. #            set gp_Out [getline "Enter name of output console?" "* misc output $gpTermCt *" ]
  896.             set gp_Out "* misc output $gpTermCt *"
  897.             set theMode "TEXT"
  898.         }
  899.  
  900.         if { $gp_Out == "" } {set gp_Out $gp_Console }
  901.         
  902.         if {  [lsearch $wins $gp_Out ]  < 0 } { 
  903.             new  -n $gp_Out -m $theMode
  904.             #set wins [winNames]
  905.             set gp_Out [lindex [winNames] 0]
  906.         } else {
  907.             #catch [ bringToFront $gp_Out ] ans
  908.             #if { ![info exists ans] } { return }
  909.         }
  910.         
  911.         insertText -w $gp_Out $outit
  912.         GP_Console
  913.         if { $it == "Unable to find process" } GP_Quit
  914.        return 0
  915.     }
  916.     
  917.     proc GP_INSEhandler {it} {
  918.     global gp_Console gp_TYPE gp_CREA GnuplotSig
  919.         set res [GP_filtercurlyq $it]
  920.         set wins [winNames]
  921.         if { ( "$res" != "\n" ) & ( "$res" != "" ) & ( "$res" != "\r" ) } {
  922.             if { [ lsearch $wins $gp_Console  ] >= 0} {
  923.                 bringToFront $gp_Console    
  924.             }        
  925.         }        
  926.         
  927.         goto [maxPos]        
  928.         insertText -w $gp_Console $res
  929.         
  930.        
  931.        set paren  [string first "()" $res ]
  932.  
  933.        if { $paren >= 1 } {
  934.            goto [expr [maxPos] - $paren + 2]
  935.        }
  936.               
  937.        if { "$res" == "\r" }  {
  938.           GP_SendCommand "" 3600
  939.        } elseif { "$res" == "\n" }  {
  940.           GP_SendCommand "" 3600 
  941.        } elseif { "$res" == "" }  {
  942.           GP_SendCommand "" 3600
  943.        } else {
  944.             return 0
  945.        }
  946.           
  947.           
  948.     }
  949.  
  950.  
  951.    proc GP_SendPath { dummyVar } {
  952.        global gp_cwd
  953.       # display current path on status bar
  954.          set gp_cwd [ GP_filtercurlyq $dummyVar ]
  955.          message "Current gnuplot Path ==> $gp_cwd"
  956.     }
  957.  
  958.     proc GP_ConsoleH { dummyVar } { 
  959.        GP_Console   
  960.        # this is a dummy routine
  961.     }  
  962.  
  963.     proc GP_NewWindowH { dummyVar } { 
  964.         switchTo 'ALFA'
  965.         GP_NewWindow   
  966.        # this is a dummy routine
  967.     }  
  968.  
  969.     proc GP_ActivateH { dummyVar } { 
  970.        GP_Activate   
  971.        # this is a dummy routine
  972.     }  
  973.  
  974.     proc GP_CloseH { dummyVar } { 
  975.        GP_Quit   
  976.        # this is a dummy routine
  977.     }  
  978.  
  979.  } else { set GPLTmodeVars(EventHandler) 0 }
  980.  
  981.  
  982. #############################################################################
  983. #
  984. #  Find and launch gnuplot
  985. #
  986. #
  987.  
  988. proc GP_Check {} {
  989.     global GnuplotMenu gp_Launched GPLTmodeVars
  990.                    
  991.     # Check if gnuplot app is running.  If not, open the app named in 
  992.     # $ (if defined) or have the user select an app via a
  993.     # standard file dialog.  Leave the gnuplot app in the background.
  994.    
  995.       if {![catch {app::launchAnyOfThese {GPSE GPLT} GnuplotSig}]} {
  996.         set gp_Launched 1
  997.         enableMenuItem $GnuplotMenu "quit gnuplot" on
  998.         enableMenuItem $GnuplotMenu "graph" on
  999.         enableMenuItem $GnuplotMenu "history" on
  1000.         enableMenuItem $GnuplotMenu "saveSettings" on  
  1001.         enableMenuItem gnuplotOptions "setPointSize..." on  
  1002.         enableMenuItem $GnuplotMenu "setWorkingFolder..." on
  1003.         enableMenuItem $GnuplotMenu "choosePlotFile..."     on
  1004.         return 0
  1005.     } else {
  1006.         return -1
  1007.     }
  1008. }
  1009.  
  1010. #############################################################################
  1011. #
  1012. #  Goto command window
  1013. #
  1014. proc GP_Console {  } {
  1015. global gp_Console win::Modes  GPLTmodeVars 
  1016. global gp_Launched gp_Prompt 
  1017.    
  1018.     # Check if gnuplot app is running.  If not, open the app named in 
  1019.     # $ (if defined) or have the user select an app via a
  1020.     # standard file dialog.  Leave the gnuplot app in the background.
  1021.    
  1022.     set wins [winNames]
  1023.     if { [lsearch $wins $gp_Console ]  >= 0} {
  1024.         bringToFront $gp_Console
  1025.         goto [maxPos]
  1026.     } else   {
  1027.         eventHandler GPIC cbye "GP_CloseH"
  1028.         GP_NewConsole
  1029.     }  
  1030. }
  1031.  
  1032.  
  1033. #############################################################################
  1034. #
  1035. #  Create  command window
  1036. #
  1037. proc GP_NewConsole { } {
  1038.     global win::Modes gp_Console gp_Graph win::Modes gp_Path
  1039.     global  GPLTmodeVars gp_Launched gp_GEOM GP_GraphMenu
  1040.     global gp_Prompt  gp_cwd GnuplotMenu  gp_home gp_scriptItems
  1041.  
  1042.     if {[llength $gp_GEOM] != "4" } {            
  1043.         GP_Readme
  1044.         new -n $gp_Console -m GPLT
  1045.         set gp_GEOM [ getGeometry $gp_Console ] 
  1046.     }   
  1047.     set wd [lindex $gp_GEOM 2]
  1048.     set ht [lindex $gp_GEOM 3]
  1049.     set top [lindex $gp_GEOM 1]
  1050.     set left [lindex $gp_GEOM 0]
  1051.     set gY [expr $top - 15]
  1052.     set gX [expr $left + $wd + 5]
  1053.     set gW [expr 72 ]
  1054.     set gH [expr 50 ]
  1055.  
  1056.     set wins [winNames]    
  1057.     if {  [lsearch $wins $gp_Console ]  < 0 } { 
  1058.         new -g $left $top $wd $ht -n $gp_Console -m GPLT
  1059.     }
  1060.     catch { setWinInfo -w $gp_Console shell 1 } jjj
  1061.     GP_GraphButton
  1062.     if { $GPLTmodeVars(LiveHist) } GP_DumpHistory
  1063.     insertText -w $gp_Console  "\nWelcome to Alpha's gnuplot 3.6 shell.\n" 
  1064.     GP_Check
  1065.     bringToFront $gp_Console
  1066.     
  1067.      set res [ GP_STDERR ""  3600 ]
  1068.      insertText -w $gp_Console "$res"
  1069.      
  1070.      # The following is a huge kludge...to deal with accidentally
  1071.      # closing the gnuplot window
  1072.      if    { $res == "" }    {
  1073.              GP_Results "gnuplot> "
  1074.      }
  1075.      # end kludge
  1076.           
  1077.      # Now setup the CLIE
  1078.      if {[string first "Using threaded console."  $res ] != {-1} \
  1079.        | [string first "ppc" [string tolower $res ] ] != {-1}  } { 
  1080.            set ress [GP_STDERR "" 3600 ]
  1081.     }
  1082.  
  1083.     set gp_home "$gp_cwd"
  1084.     append gp_home "Scripts:*" 
  1085.  
  1086.  
  1087.      set cdir [pwd]
  1088.      set gp_Path "$gp_home"
  1089.    
  1090.     GP_RebuildScriptMenu
  1091.     cd "$cdir"
  1092.     
  1093.      set gp_home [string range "$gp_home" 0 [expr [string length "$gp_home" ] -2 ] ]
  1094.      message "Current gnuplot Path ==> $gp_cwd"
  1095.      
  1096. }
  1097.  
  1098.  
  1099. ################################################################################
  1100. #
  1101. #  Rebuild the script menu 
  1102. #      
  1103. #
  1104.  
  1105. proc GP_RebuildScriptMenu {  }   {
  1106. global gp_cwd GP_GraphMenu gp_scriptItems gp_openItems gp_Path
  1107.  
  1108.     set gp_scriptItems [list]
  1109.     set gp_openItems [list]
  1110.     set gp_home "$gp_Path"
  1111.  
  1112.     set gp_sl [ GP_ScriptList "$gp_home" "Scripts" ]
  1113.     set gp_sm [concat menu -m -n "Scripts" -p GP_ScriptMenuItems [list "$gp_sl"]  ]
  1114.     
  1115.     # kill the current floating menu (if any)
  1116.     GP_KillGraphButton
  1117.     
  1118.     menu  -n "$GP_GraphMenu" -p GnuplotMenuItem [list \
  1119.       "gnuplot" \
  1120.       "(-" \
  1121.       {menu -m -s -n "Settings" -p GnuplotMenuItem  {\
  1122.           "line styles...&" \
  1123.         "text format...&" \
  1124.           "labels...&" \
  1125.           "offsets...&" \
  1126.       }}\
  1127.        "(-" \
  1128.        "$gp_sm" \
  1129.     ]
  1130.      
  1131.     GP_GraphButton
  1132. }
  1133.    
  1134.     
  1135. ################################################################################
  1136. #
  1137. #  Generate a new script window 
  1138. #      
  1139. #
  1140.  
  1141. proc GP_NewWindow {  } {
  1142.     set wname "Untitled.gp"
  1143.     new -n $wname -m GPLT
  1144.     GP_uFD
  1145.     insertText "#\r"
  1146.     setWinInfo -w $wname dirty 0
  1147.    #
  1148. }
  1149.  
  1150.  
  1151.  
  1152.  
  1153. #############################################################################
  1154. #
  1155. #  Tell gnuplot to quit
  1156. #
  1157.  
  1158. proc GP_Quit {} {
  1159.     global gp_Console  
  1160.  
  1161.     switchTo 'ALFA'
  1162.     set wins [winNames]
  1163.     if { [set winThere [lsearch $wins $gp_Console ] ] >= 0} {
  1164.         set name [lindex $wins $winThere]
  1165.         bringToFront $name
  1166.         killWindow
  1167.     } 
  1168.  
  1169. }
  1170.  
  1171.  
  1172. #############################################################################
  1173. #
  1174. #  Switch to gnuplot
  1175. #
  1176.  
  1177. proc GP_Activate {  } {
  1178.     global   GnuplotSig 
  1179.     
  1180.     if { ![GP_Check] } { 
  1181.         switchTo \'$GnuplotSig\' 
  1182.     }    
  1183. }
  1184.  
  1185.  
  1186. #############################################################################
  1187. #
  1188. #  Carriage return for command window
  1189. #
  1190.  
  1191. proc GP_CarriageReturn {} {
  1192.     global gp_CommandHist gp_CommandNum  gp_Console gp_Hist gp_Graph 
  1193.  
  1194.     #enter only if cr in console window...
  1195.     set wins [winNames]
  1196.     if { [lsearch $wins $gp_Console ]  == 0  } {
  1197.         setWinInfo -w $gp_Console dirty 0            
  1198.         set pos [getPos]
  1199.     
  1200.         # I look for > and : instead of the proper prompts... Hmmm...
  1201.         # if -1 then we are not on an input line...
  1202.         # or we could be waiting for a pause...
  1203.         # which should be on the last line...        
  1204.         set ind [string first ">" [getText [lineStart $pos] $pos] ]
  1205.         if {$ind < 0} {
  1206.             set ind [string first ":" [getText [lineStart $pos] $pos] ]
  1207.             if {$ind < 0} {
  1208.                  endOfBuffer
  1209.                  # just send a cr to the server
  1210.                  insertText "\r"
  1211.                  GP_SendCommand [getText [lineStart $pos] $pos] 400
  1212.                  return 
  1213.             }
  1214.         }
  1215.         set lStart [expr [lineStart $pos]+$ind+2]
  1216.         endOfLine
  1217.         set lEnd  [getPos]  
  1218.         set scriptName [getText $lStart $lEnd]
  1219.         insertText "\r"
  1220.         # if not on last line, then replace text on last line...
  1221.         GP_SendCommand "$scriptName"  102
  1222.     } elseif {[lsearch $wins $gp_Hist ] == 0} {
  1223.         # execute the current command in the history window...
  1224.         GP_HistgotoMatch
  1225.     } else {
  1226.         insertText "\r"
  1227.     }
  1228. }
  1229.  
  1230.  
  1231.  
  1232. #############################################################################
  1233. #
  1234. #  Filter curlyq's out of sting...We may need to be smarter 
  1235. #    about this later
  1236. #
  1237. proc GP_filtercurlyq { it } {
  1238.  
  1239.   set from [string first "“" $it]
  1240.   set to [string first "”" $it]
  1241.   set ans [string range $it [expr $from + 1] [expr $to - 1] ]
  1242.   if { ![expr [string length $ans] -1 ] } { 
  1243.       regexp -nocase {[a-z0-9]} $ans nans
  1244.       if {[info exists nans]} {
  1245.           set ans $nans
  1246.       } else {
  1247.           set ans ""
  1248.       }
  1249.       
  1250.       
  1251.   }
  1252.   
  1253.   return $ans
  1254. }
  1255.  
  1256. #############################################################################
  1257. #
  1258. #  Extract current gnuplot path from event reply
  1259. #
  1260.  
  1261. proc GP_ExtractPath { ans } {
  1262.     global gp_cwd 
  1263.     
  1264.     # We need to be tricky since I'm not sure if Dave is sending the
  1265.     # path in an alis, or as a string
  1266. #    regexp {“(.*)(”.*“)(.*)”} "$ans" dummy spec1 spec2 spec3   
  1267.     
  1268.     set frst [ string first "PSTR:" "$ans" ]
  1269.     set lst [ string first "TERM:" "$ans" ]
  1270.     
  1271.     if { ($frst > 0) } {
  1272.         if { $lst <= 0 } { set lst [string length $ans ] }
  1273.         set ans [string range "$ans" $frst $lst ]
  1274.         regexp {“(.*)”} "$ans" dummy  spec3   spec1 
  1275.         if {[info exists spec3]} {
  1276.            set ngp_cwd $spec3
  1277.            if {$ngp_cwd != "" } {
  1278.                set gp_cwd "$ngp_cwd"
  1279.             return 0
  1280.            }         
  1281.        }
  1282.    }
  1283.       
  1284.    regexp {«(.*)»} "$ans" dummy spec
  1285.    if {[info exists spec]} {
  1286.    set ngp_cwd [specToPathName $spec]
  1287.    if {$ngp_cwd != "" } {
  1288.            set gp_cwd "$ngp_cwd"
  1289.         return 0
  1290.        }         
  1291.    }
  1292. }    
  1293.   
  1294.     
  1295.  
  1296. #############################################################################
  1297. #
  1298. #  Send a command to gnuplot and return stderr!
  1299. #
  1300.  
  1301. proc GP_STDERR { mycommand tmout } {
  1302. global  gp_cwd  GPLTmodeVars GnuplotSig gp_TYPE gp_CREA
  1303.  
  1304.     if { ! $GPLTmodeVars(EventHandler) } {
  1305.         catch { AEBuild -t $tmout -r \'$GnuplotSig\' GPSE  "exec" ---- \
  1306.                [curlyq $mycommand] {CREA:} "$gp_CREA" \
  1307.                {TYPE:} "$gp_TYPE" } ans 
  1308.     } else {
  1309.         catch { AEBuild -t $tmout -r \'$GnuplotSig\' GPSE  "exec" ---- \
  1310.                [curlyq $mycommand] {CLIE:} "ALFA" {CREA:} "$gp_CREA" \
  1311.                {TYPE:} "$gp_TYPE" } ans 
  1312.     } 
  1313.     if { $ans == "Unable to find process"  }  GP_Quit        
  1314.     GP_ExtractPath $ans
  1315.     return [GP_filtercurlyq $ans]
  1316. }
  1317.  
  1318.  
  1319. #############################################################################
  1320. #
  1321. #  Send a command to gnuplot  
  1322. #
  1323.  
  1324. proc GP_SendCommand { mycommand tmout} {
  1325. global GPLTmodeVars GnuplotMenu  gp_CommandHist gp_Rsp  gp_CommandNum  
  1326. global gp_Prompts gp_Launched 
  1327.     
  1328.     watchCursor
  1329. #    GP_Console
  1330.       
  1331.      set tmout 300
  1332.     #display command on the last line of the console if its not already there
  1333.    GP_DispCommand "$mycommand"
  1334.       if { [string trim $mycommand '\r'] != {} } {
  1335.         GP_AddToHist $mycommand
  1336.     }
  1337.  
  1338.    # send gnuplot a command
  1339.    # display the stderr results on the screen
  1340.    # The eventHandler above will display the stdout results first
  1341.    set stderr [GP_STDERR "$mycommand\r"  $tmout ]
  1342.    
  1343.    # Null stderr can mean two things.  
  1344.    #   (1) a pause 
  1345.    #   (2) if no thread manager available, it could mean go back 
  1346.    #       and retrieve the stderr which will help 68k systems 
  1347.    #       work since eventHandler is broken in 6.01
  1348.    
  1349.    # This can probably be cleaned up with a little effort
  1350.    # What I'm doing in the next line is taking care of the 
  1351.    # non-threaded macs...
  1352.    # which always return "".  Its harmless otherwise.
  1353.    #if {$stderr == ""  & $mycommand != "" } { set stderr [GP_STDERR "" $tmout ] }
  1354.     #if { $GPLTmodeVars(EventHandler) == "0" &  $stderr == "" } { set stderr "gnuplot> " }
  1355.    if { $stderr != "" } { 
  1356.           GP_Results     "$stderr" 
  1357.    } else {
  1358.           #GP_Results ""
  1359.    }
  1360.          
  1361.     blink [getPos]
  1362. }
  1363.   
  1364.  
  1365. #############################################################################
  1366. #
  1367. #  Save current window and execute it in GNUPLOT, just like GNUPLOT 
  1368. #  command ;)
  1369. #
  1370.  
  1371. proc GP_SaveAndExecute {} {
  1372.  
  1373.     if {[winDirty]} {save}
  1374.  
  1375. # Get the path of the current window and it's name
  1376.     
  1377.    # Set the working directory to the current window's
  1378.    # current dir.
  1379.     set GPLTFilePath "cd \'\:"
  1380.     set GPLTFile [lindex [winNames -f] 0]
  1381.     set GPLTFP [file dirname $GPLTFile]
  1382.     append  GPLTFilePath  $GPLTFP ":\'"
  1383.  
  1384.     # use unix style file paths 
  1385.     regsub -all ":" $GPLTFilePath {/} GPLTFilePath
  1386.  
  1387.    # get the load command ready...
  1388.     set scriptName  "load \'"
  1389.     append scriptName [file tail $GPLTFile] "\'"
  1390.  
  1391.    # Change current working directory to window's
  1392.    GP_SendCommand $GPLTFilePath 600
  1393.     
  1394.    # Do the script
  1395.    GP_SendCommand $scriptName 700
  1396. }
  1397.   
  1398.  
  1399. #############################################################################
  1400. #
  1401. #  Write results to command window  
  1402.  
  1403. proc GP_Results { res } {
  1404. global gp_Console gp_cwd
  1405.         insertText -w "$gp_Console"  "\n" $res
  1406.         setWinInfo -w "$gp_Console" dirty 0
  1407.     message "Current gnuplot Path ==> $gp_cwd"
  1408. }
  1409.  
  1410.  
  1411. #############################################################################
  1412. #
  1413. #  Display or rewrite "command" to command window  
  1414.  
  1415. proc GP_DispCommand {command} {
  1416.     global   gp_Prompts gp_cwd 
  1417.     
  1418.     # This is ugly and probably not very efficient.
  1419.     
  1420.    set lst [maxPos]
  1421.    set boll [lineStart $lst]
  1422.  set curr [getPos]
  1423.    
  1424.    if { $curr >= $boll } {       
  1425.         set bol [lineStart $curr]
  1426.         set eol [nextLineStart $curr] 
  1427.          set text [getText $bol $eol]
  1428.        set ltext [getText $boll $lst]
  1429.        foreach gp $gp_Prompts {
  1430.            set c1 [string first $gp $ltext]
  1431.            set c2 [expr $lst - $boll]
  1432.            set c3 [string length $gp]
  1433.            set c4 [expr $lst - $curr] 
  1434.            set c5 [string length $command]
  1435.            if { $c1 == 0 & [expr $c2 >= $c3 | $c4 >= $c5 ] } {
  1436.                     if {[string first $command $text] == -1} {
  1437.                         set a [expr $boll + [string length $gp] ]
  1438.                         set b [string trim $command "\r"]
  1439.                         replaceText $lst  $a $b
  1440.                 } 
  1441.            } 
  1442.         }    
  1443.     }
  1444. }
  1445.  
  1446.  
  1447.  
  1448.  
  1449. #############################################################################
  1450. #
  1451. #  Send line to GNUPLOT
  1452. #
  1453.  
  1454. proc GP_DoLine {} {
  1455.     
  1456.     beginningOfLine
  1457.     set bol [getPos]
  1458.     endOfLine
  1459.     set eol [getPos]
  1460.  
  1461.     set scriptName [getText $bol $eol]
  1462.    GP_SendCommand $scriptName     800
  1463. }
  1464.  
  1465.  
  1466. #############################################################################
  1467. #
  1468. #  Send selection to GNUPLOT
  1469. #
  1470.  
  1471. proc GP_DoSelection {} {
  1472.     # Break lines into separate commands.
  1473.     foreach sN [split [getSelect] "\r"] { 
  1474.         GP_SendCommand $sN 900
  1475.     }
  1476.     
  1477. }
  1478.  
  1479.  
  1480.  
  1481.  
  1482. #############################################################################
  1483. #
  1484. #  Command History 
  1485. #
  1486.  
  1487. proc GP_PrevCommand {} {
  1488. global  gp_CommandHist gp_CommandNum gp_Hist gp_Prompt gp_MultiPrompt 
  1489. global  gp_ContPrompt gp_Console gp_Hist
  1490.     
  1491.     #enter only if cr in console window...
  1492.     set wins [winNames]
  1493.     if { [lsearch $wins "$gp_Console" ] == 0} {
  1494.  
  1495.         set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ] ]
  1496.         if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1497.             goto [expr [lineStart [getPos] ] + $ind + [string length $gp_Prompt] ]
  1498.         } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1499.             goto [expr [lineStart [getPos] ] + $ind + 
  1500.               [string length $gp_Multiprompt] ]
  1501.         } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1502.             goto [expr [lineStart [getPos] ] + $ind + [string length $gp_Contprompt] ]
  1503.         } elseif { return }
  1504.     
  1505.         incr gp_CommandNum -1
  1506.         if {$gp_CommandNum < 0} {
  1507.             incr gp_CommandNum
  1508.             endOfLine
  1509.             return
  1510.         } 
  1511.         set text [lindex $gp_CommandHist $gp_CommandNum]
  1512.         set to [nextLineStart [getPos] ]
  1513.         if {[lookAt [expr $to-1] ] == "\r"} {incr to -1}
  1514.  
  1515.         replaceText [getPos] $to $text
  1516.     } elseif { [lsearch $wins $gp_Hist ]  == 0} {
  1517.         
  1518.         set limit [nextLineStart [nextLineStart 0] ]
  1519.         if {[getPos] > $limit} {
  1520.             set limit [expr [getPos] - 1]
  1521.         }
  1522.         select [lineStart $limit] [nextLineStart $limit]
  1523.     } else {
  1524.         previousLine
  1525.     }
  1526.     
  1527. }
  1528.  
  1529. proc GP_NextCommand {} {
  1530.     global  gp_CommandHist gp_CommandNum gp_Prompt gp_MultiPrompt 
  1531.    global gp_ContPrompt gp_Console gp_Hist
  1532.     
  1533.     #enter only if cr in console window...
  1534.     set wins [winNames]
  1535.     if { [lsearch $wins "$gp_Console"  ]  == 0} {
  1536.  
  1537.         set text [getText [lineStart [getPos] ] [nextLineStart [getPos] ]]
  1538.         if {[set ind [string first $gp_Prompt $text] ] == 0} {
  1539.             goto [expr [lineStart [getPos] ] + $ind + 9]
  1540.         } elseif {[set ind [string first $gp_MultiPrompt $text] ] == 0} {
  1541.                 goto [expr [lineStart [getPos] ] + $ind + 11]
  1542.         } elseif {[set ind [string first $gp_ContPrompt $text] ] == 0} {
  1543.                 goto [expr [lineStart [getPos] ] + $ind + 3]
  1544.         } else  { 
  1545.             endOfBuffer
  1546.             return 
  1547.         }
  1548.     
  1549.         incr gp_CommandNum
  1550.         if {$gp_CommandNum > [llength $gp_CommandHist]} {
  1551.             incr gp_CommandNum -1
  1552.             return
  1553.         }
  1554.         set text [lindex $gp_CommandHist $gp_CommandNum]
  1555.         set to [nextLineStart [getPos] ]
  1556.         if {[lookAt [expr $to-1] ] == "\r"} {incr to -1}
  1557.         replaceText [getPos] $to $text
  1558.     } elseif { [lsearch $wins $gp_Hist  ]  == 0} {
  1559.             set pos [getPos]
  1560.             if {$pos < [nextLineStart 0]} {
  1561.                 set pos [nextLineStart 0]
  1562.             }
  1563.             if {[nextLineStart $pos] != [maxPos]} {
  1564.                 select [nextLineStart $pos] [nextLineStart [nextLineStart $pos] ]
  1565.             }
  1566.         } else {
  1567.       # mv cusor down...
  1568.             nextLine
  1569.     }    
  1570. }
  1571.  
  1572.  
  1573.  
  1574. #############################################################################
  1575. #
  1576. #  Edit current window in GNUPLOT
  1577. #
  1578.  
  1579. proc GP_EditFile {} {
  1580. global GnuplotSig 
  1581.  
  1582.     if { ![GP_Check] } {
  1583.         set thisWin  [lindex [winNames] 0]
  1584.         if {[winDirty]} {
  1585.             if {[askyesno "Save '$thisWin'?"] == "yes"} {
  1586.                 save
  1587.             } else { return }     }
  1588.         set thisWin  [lindex [winNames -f ] 0]
  1589.         fileMenuProc File close
  1590.         if {[catch {sendOpenEvent -n \'$GnuplotSig\' $thisWin }] } {
  1591.         } else { switchTo \'$GnuplotSig\'     }
  1592.    }
  1593. }
  1594.  
  1595.  
  1596. #############################################################################
  1597. #
  1598. #  change behavior of modifyModeFlags
  1599. #
  1600.  
  1601.     
  1602. proc GP_modifyModeFlags {{title ""}} {
  1603.     global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  1604.     global GnuplotMenu  gp_Graph gp_Console  gp_Hist gp_floatmenu
  1605.     
  1606.     set wins [winNames]
  1607.     if { [lsearch $wins "$gp_Console" ]  >= 0}  {
  1608.         set gp_GEOM [ getGeometry "$gp_Console" ]
  1609.     }
  1610.     
  1611.     if { [lsearch $wins $gp_Hist] >= 0 } {
  1612.         set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1613.     }
  1614.     
  1615.     set gp_modflag 1
  1616.        
  1617.     if { $GPLTmodeVars(LiveHist) } { 
  1618.         set wins [winNames]
  1619.         if { [lsearch $wins "$gp_Console"  ]  >= 0} {
  1620.             GP_DumpHistory
  1621.         } 
  1622.     } else {
  1623.           set wins [winNames]
  1624.         if {[lsearch $wins $gp_Hist  ]  >= 0} {
  1625.             bringToFront $gp_Hist
  1626.             killWindow 
  1627.         } 
  1628.     }
  1629.     if { $GPLTmodeVars(EventHandler) } { 
  1630.     } else {
  1631.         set jj1 "The event handler is broken in Alpha (68k).
  1632.         set jj2 "You may need to disable event handling until it is fixed."
  1633.        alertnote $jj1 $jj2
  1634.     }
  1635.     if { $GPLTmodeVars(GraphButton) } { 
  1636.         GP_GraphButton
  1637.     } else {
  1638.         GP_KillGraphButton
  1639.     }
  1640.     # This file is sourced when appropriate by Alpha, 
  1641.     # it should not happen here.
  1642.     #catch {  source $PREFS:GPLTPrefs.tcl } jjj
  1643.     catch {    bringToFront "$gp_Console" } jjj
  1644. }
  1645.  
  1646. #############################################################################
  1647. #
  1648. #  closeHook procedure so that gnuplot is quit 
  1649. #  whenever the user closes the console window.  Also ask about 
  1650. #  saving the history list when the console is closed.
  1651. #
  1652. #
  1653.     
  1654. proc GP_CloseHook    {name} {
  1655.     global GnuplotMenu GPLTmodeVars PREFS modifiedArrayElements
  1656.     global gp_CreatorList gp_TypeList gp_Console gp_Graph gp_Hist 
  1657.     global gp_CreatorNames gp_CommandNum gp_Launched GnuplotSig modifiedVars
  1658.     global gp_GEOM gp_HistGEOM modifiedVars
  1659.     
  1660.     if { [string first "$gp_Console" $name] == 0    } {
  1661.  
  1662.                if    {$gp_CommandNum != 0 && ! $GPLTmodeVars(NevrSavHist) } {
  1663.             GP_DumpHistory
  1664.             set ans [askyesno -c "Save    gnuplot command History?" ]
  1665.         } else {    set ans "yes" }
  1666.         
  1667.         GP_OffSet
  1668.         switch -exact [string tolower $ans] {
  1669.             "cancel"   { GP_Console; return $result }
  1670.             "no"       { GP_ClearHistory }
  1671.             "yes"       {     
  1672.                 catch { setWinInfo -w $gp_Hist read-only 0 } jj                                        
  1673.                 catch { setWinInfo -w $gp_Hist dirty 1 } jj
  1674.                 catch { bringToFront $gp_Hist } jj
  1675.                 if { $jj == 0 } { 
  1676.                     catch { saveAs "history.gp" } jj
  1677.                 }
  1678.                 catch { setWinInfo -w $gp_Hist dirty 0 } jj                                        
  1679.                 catch { setWinInfo -w $gp_Hist read-only 1 } jj
  1680.                 GP_ClearHistory
  1681.             }
  1682.         } 
  1683.             #end case
  1684. #        if {$gp_Launched    !=    0 } { 
  1685.                 catch { sendQuitEvent \'$GnuplotSig\' } hhh  
  1686.                 lappend modifiedVars  GnuplotSig 
  1687. #            } 
  1688.                set gp_Launched 0
  1689.              set wins [winNames]
  1690.         if { [lsearch $wins $gp_Hist  ]  >= 0} {
  1691.             bringToFront $gp_Hist
  1692.             killWindow 
  1693.         } 
  1694.         lappend modifiedVars   gp_GEOM 
  1695.         lappend modifiedVars   gp_HistGEOM 
  1696.  
  1697.     } elseif {[string first $gp_Hist    $name] == 0} {
  1698.         set wins [winNames]
  1699.         if { [lsearch $wins "$gp_Console" ]  >= 0} {
  1700.             set GPLTmodeVars(LiveHist) 0
  1701.         } 
  1702.     }
  1703.     
  1704.  
  1705. #############################################################################
  1706. #
  1707. #  Redefine the deactivateHook procedure so that gnuplot is quit 
  1708. #  whenever the user closes the console window.  Also ask about 
  1709. #  saving the history list when the console is closed.
  1710. #
  1711. #
  1712.     
  1713. proc GP_DeactivateHook    {name} {
  1714.     global  gp_Hist GPLTmodeVars gp_Console gp_Graph
  1715.     global  gp_GEOM gp_HistGEOM
  1716.     if    { [string first $gp_Hist $name] == 0    } {
  1717.         set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1718.           endOfBuffer
  1719.     } elseif {[string first "$gp_Console" $name] == 0} {
  1720.         set gp_GEOM [getGeometry "$gp_Console" ]
  1721.     } 
  1722.  
  1723. #############################################################################
  1724. #
  1725. #  Redefine the activateHook procedure so that gnuplot is quit 
  1726. #  whenever the user closes the console window.  Also ask about 
  1727. #  saving the history list when the console is closed.
  1728. #
  1729. #
  1730. proc GP_ActivateHook    {name} {
  1731.     global  gp_Hist gp_Graph gp_Console modifiedArrayElements
  1732.     global  mode gp_cwd GPLTmodeVars mode gp_modflag gp_GEOM
  1733.         
  1734.     if    { [string first "$gp_Console" $name] == 0} {
  1735.         changeMode [set win::Modes([lindex [winNames] 0]) GPLT]
  1736.         set gp_GEOM [ getGeometry "$gp_Console" ]
  1737.     } elseif    { [string first $gp_Hist $name] == 0} {
  1738.         set gp_HistGEOM [ getGeometry "$gp_Hist" ]
  1739.     }
  1740.     
  1741.     message "Current gnuplot Path ==> $gp_cwd"
  1742.  
  1743.  
  1744.  
  1745.  
  1746. ###########################################################################
  1747. #
  1748. # In GNUc mode, cmd-double-click highlights area btween consecutive 
  1749. # gnuplot prompts
  1750. #
  1751.  
  1752. proc GPLT::DblClick {from to} {
  1753.    
  1754.     global gp_Prompts
  1755.     
  1756.     # First find "gnuplot> " prompt above and below cursor entry...
  1757.     # don't forget to deal with "multiplot> " and "> "
  1758.  
  1759.     set gp1 [list]
  1760.     foreach gp $gp_Prompts {lappend gp1 [search -n -f 0 -r 1   $gp $from] }
  1761.     set firstmatch [lindex [lindex $gp1 0 ] 0]
  1762.     foreach el $gp1 { if {[lindex $el 1] > $firstmatch } { 
  1763.          set firstmatch [lindex $el 0] } }    
  1764.  
  1765.     if {$firstmatch == {}} {
  1766.         message "You are not between prompts" 
  1767.         return 
  1768.     } else {
  1769.         
  1770.         set firstmatch [nextLineStart $firstmatch]
  1771.         endOfBuffer
  1772.         set lastmatch [getPos ]
  1773.         set gp1 [list]
  1774.         foreach gp $gp_Prompts {lappend gp1 [search -n -f 1 -r 1   $gp $from] }
  1775.         foreach el $gp1 {if {[lindex $el 1]!={} & [lindex $el 0]< $lastmatch } { 
  1776.                set lastmatch $el } 
  1777.        }
  1778.          if {$lastmatch == {}} {
  1779.             message "You are not between prompts" 
  1780.             return 
  1781.         } else { 
  1782.         
  1783.         goto $lastmatch
  1784.         beginningOfLine
  1785.         select $firstmatch [getPos] }
  1786.     }
  1787. }
  1788.  
  1789.  
  1790.  
  1791. #############################################################################
  1792. #
  1793. #  Select creator from list
  1794. #
  1795.  
  1796. proc GP_SelectCreator {} {
  1797. global gp_CreatorNames  gp_CreatorList   gp_TypeList GPLTmodeVars  
  1798. global setOutputCreator modifiedArrayElements modifiedVars
  1799. global gp_CREA gp_TYPE
  1800.  
  1801.     set crea [listpick -p "Select output file creator:" $gp_CreatorNames  ]
  1802.    set creator [lindex $gp_CreatorList [lsearch  $gp_CreatorNames $crea] ]
  1803.    set type [lindex $gp_TypeList [lsearch  $gp_CreatorNames $crea] ]
  1804.    if {$creator == {} } {
  1805.          set gp_CREA 'ALFA'
  1806.          set gp_TYPE 'TEXT' 
  1807.    } else { 
  1808.        set gp_CREA $creator
  1809.        set gp_TYPE $type
  1810.    }
  1811.     lappend modifiedVars  gp_TYPE
  1812.     lappend modifiedVars  gp_CREA
  1813.     lappend modifiedVars  gp_CreatorList 
  1814.     lappend modifiedVars  gp_TypeList
  1815.     lappend modifiedVars  gp_CreatorNames 
  1816. }
  1817.  
  1818.  
  1819. #############################################################################
  1820. #
  1821. #  Add creator to list from file dialog
  1822. #
  1823.  
  1824. proc GP_AddCreator {} {
  1825. global gp_CreatorNames  gp_CreatorList  GnuplotMenu gp_TypeList 
  1826. global GPLTmodeVars modifiedVars modifiedArrayElements
  1827. global gp_CREA gp_TYPE
  1828.    
  1829.    set fname [getfile "Select file type for creator"] 
  1830. #  add to creator list
  1831.    if {[getFileType $fname]=="APPL"} {
  1832.        alertnote "Sorry, but that was an application. \rTry again."
  1833.        return
  1834.    }
  1835.    
  1836.    if {$fname != {}} {
  1837.        set nm [getline "What do you wish to call it?" [file tail $fname ] ]
  1838.         if {$nm != {} } {   
  1839.                 set gp_CREA  [getFileSig $fname]
  1840.                 set gp_TYPE  [getFileType $fname]
  1841.                 lappend gp_CreatorList  $gp_CREA
  1842.                 lappend gp_TypeList     $gp_TYPE
  1843.                 lappend gp_CreatorNames $nm
  1844.                 enableMenuItem  setOutputCreator "Select..." on
  1845.                 enableMenuItem  setOutputCreator "Delete..." on
  1846.                 lappend modifiedVars  gp_TYPE
  1847.                 lappend modifiedVars  gp_CREA
  1848.                 lappend modifiedVars  gp_CreatorList 
  1849.                 lappend modifiedVars  gp_TypeList 
  1850.                 lappend modifiedVars  gp_CreatorNames 
  1851.             }
  1852.    }
  1853.      
  1854.  
  1855. }
  1856.  
  1857. #############################################################################
  1858. #
  1859. #  Remove creator from list
  1860. #
  1861.  
  1862. proc GP_DeleteCreator {} {
  1863. global gp_CreatorNames GnuplotMenu gp_CreatorList  gp_TypeList 
  1864. global GPLTmodeVars modifiedVars modifiedArrayElements
  1865. global gp_CREA gp_TYPE
  1866.  
  1867.     set crea [listpick -p "Select creator to be deleted:"  $gp_CreatorNames ]
  1868.  
  1869.       if {$crea != {}} {
  1870.     #  now remove this creator from both lists....
  1871.         set creatorInd [lsearch  $gp_CreatorNames $crea]
  1872.         set crea [ lindex $gp_CreatorList $creatorInd]
  1873.         set gp_CreatorNames [ lreplace $gp_CreatorNames $creatorInd $creatorInd ]
  1874.         set gp_CreatorList  [ lreplace $gp_CreatorList  $creatorInd $creatorInd ]
  1875.         set gp_TypeList     [ lreplace $gp_TypeList     $creatorInd $creatorInd ]
  1876.     
  1877.         if {$gp_CREA == $crea } {
  1878.             set gp_CREA 'ALFA'
  1879.             set gp_TYPE 'TEXT'
  1880.         } 
  1881.         lappend modifiedVars  gp_TYPE
  1882.         lappend modifiedVars  gp_CREA
  1883.         lappend modifiedVars  gp_CreatorList 
  1884.         lappend modifiedVars  gp_TypeList 
  1885.         lappend modifiedVars  gp_CreatorNames 
  1886.     }
  1887.     
  1888.     if {[llength $gp_CreatorList] == 0} {
  1889.         enableMenuItem  setOutputCreator "Select..." off
  1890.         enableMenuItem setOutputCreator "Delete..." off
  1891.     }
  1892. }
  1893.  
  1894.  
  1895. #############################################################################
  1896. #
  1897. #  Add command to history list
  1898. #
  1899.  
  1900. proc GP_AddToHist  { cmmd } {
  1901. global gp_CommandHist gp_CommandNum GnuplotMenu 
  1902. global GP_Console gp_Hist GPLTmodeVars
  1903.     
  1904.     enableMenuItem gnuplotOptions "clearHistory" on
  1905.     lappend gp_CommandHist $cmmd
  1906.     set gp_CommandNum [llength $gp_CommandHist]
  1907.     
  1908.     if { $GPLTmodeVars(LiveHist) } {
  1909.         # if history list active then append $cmmd on last line
  1910.         set wins [winNames]
  1911.         if { [lsearch $wins $gp_Hist ]  >= 0} {
  1912.              setWinInfo -w $gp_Hist dirty 1
  1913.              setWinInfo -w $gp_Hist  read-only 0
  1914.             insertText -w $gp_Hist "$cmmd\r"
  1915.              setWinInfo -w $gp_Hist  dirty 0
  1916.              setWinInfo    -w $gp_Hist  read-only 1
  1917.         } else {
  1918.             GP_DumpHistory
  1919.             bringToFront "$gp_Console"
  1920.         }
  1921.         
  1922.     }
  1923. }
  1924.  
  1925.  
  1926. #############################################################################
  1927. #
  1928. #  Clear History list 
  1929. #
  1930.  
  1931. proc GP_ClearHistory {} {
  1932.     global  GnuplotMenu gp_CommandHist gp_CommandNum  gp_Hist
  1933.  
  1934.     set gp_CommandHist [list]
  1935.     set gp_CommandNum "0"
  1936.     enableMenuItem gnuplotOptions "clearHistory" off    
  1937.     set wins [winNames]
  1938.     if { [lsearch $wins $gp_Hist ] >= 0} {
  1939.         bringToFront $gp_Hist
  1940.         killWindow 
  1941.     }
  1942. }
  1943.  
  1944.  
  1945. #############################################################################
  1946. #
  1947. #  Write History list into a window of its own.
  1948. #
  1949.  
  1950. proc GP_DumpHistory {} {
  1951.     global gp_CommandHist gp_CommandNum gp_Console 
  1952.     global win::Modes GPLTmodeVars gp_Console gp_Hist  
  1953.     global gp_GEOM
  1954.    
  1955.     set wins [winNames]
  1956.     set nw [ llength $wins ]
  1957.  
  1958.     if { [lsearch $wins $gp_Hist ]  == -1} {
  1959.         
  1960.         set l [ expr [lindex $gp_GEOM 0] + 12 + [lindex $gp_GEOM 2] ]
  1961.         set t [ expr [lindex $gp_GEOM 1] + 65 ]
  1962.         set w 96
  1963.         set h [ expr [lindex $gp_GEOM 3] - 65 ]
  1964.         new -n $gp_Hist -g $l $t $w $h -m GPLT
  1965.         set gp_HistGEOM [getGeometry]        
  1966.         GP_uFD
  1967.         set scriptName "# (<cr> to send to gnuplot)\r#-----\r"
  1968.         foreach word $gp_CommandHist  {append  scriptName  $word "\r" }
  1969.         insertText  -w $fileName $scriptName
  1970.          setWinInfo dirty 0
  1971.          setWinInfo read-only 1
  1972.     } else {
  1973.         bringToFront $gp_Hist
  1974.     }
  1975. }
  1976.  
  1977.     
  1978.  
  1979. ################################################################################
  1980. #
  1981. #  Insert File Description---use Vince's if possible.  
  1982. #      this used in creating new window and in dumping history list
  1983. #
  1984.  
  1985. proc GP_uFD { } {
  1986.     #catch {userFileDescription } ans 
  1987.     #if {     $ans != ""    }  {
  1988.          insertText "#\r#\r#     " [join [mtime [now] long] ] "\r"
  1989.          nextLine
  1990.     #}
  1991.    endOfBuffer
  1992. }
  1993.  
  1994.  
  1995. ################################################################################
  1996. #
  1997. #  Clear a few globals...
  1998. #
  1999. #
  2000. #
  2001. proc GP_Clear {} {
  2002.     global PREFS  GPLTmodeVars
  2003.     global  gp_CreatorList gp_CreatorNames  
  2004.     global gp_GEOM gp_HistGEOM modifiedVars
  2005.     global gp_CREA gp_TYPE
  2006.  
  2007.     if { [info exists gp_GEOM] } { set gp_GEOM [list] }      
  2008.     if { [info exists gp_CreatorList] } { unset gp_CreatorList }      
  2009.     if { [info exists gp_TypeList] } { unset gp_TypeList }      
  2010.     if { [info exists gp_CreatorNames] } { unset gp_CreatorNames }      
  2011.     if { [info exists gp_HistGEOM] } { unset gp_HistGEOM  }      
  2012.     if { [info exists gp_CREA] } { unset gp_CREA  }      
  2013.     if { [info exists gp_TYPE] } { unset gp_TYPE  }      
  2014.     
  2015.     ensureset gp_CreatorList [list ALFA GPLT ] 
  2016.     ensureset gp_TypeList [list TEXT TEXT ] 
  2017.     ensureset gp_CreatorNames [list alpha gnuplot] 
  2018.     ensureset gp_CREA ALFA
  2019.     ensureset gp_TYPE TEXT
  2020.     ensureset gp_GEOM [list]
  2021.     ensureset gp_HistGEOM [list ]
  2022.     
  2023.     if { [llength $gp_CreatorList] == 0 \
  2024.       || [llength $gp_CreatorList] != [llength $gp_CreatorNames] \
  2025.       || [llength $gp_CreatorList] != [llength $gp_TypeList]} {
  2026.             set gp_CreatorList [list]
  2027.             set gp_TypeList [list]
  2028.             set gp_CreatorNames [list]
  2029.     }
  2030.  
  2031.     lappend modifiedVars gp_CreatorNames gp_TypeList gp_CreatorList 
  2032.     lappend modifiedVars gp_HistGEOM gp_GEOM
  2033.     lappend modifiedVars gp_TYPE gp_CREA
  2034.     #catch { source $PREFS:gnuplotMode.tcl } blah
  2035.     #catch { source $HOME:Tcl:Modes:gnuplotMode.tcl } blah
  2036. }
  2037.  
  2038.  
  2039. ################################################################################
  2040. #
  2041. #  History goto match...
  2042. #
  2043. #
  2044. #
  2045.  
  2046. proc GP_HistgotoMatch {} {
  2047.    set frst [lineStart [getPos] ]
  2048.    endOfLine
  2049.    set lst  [getPos]
  2050.     endOfBuffer
  2051.     beginningOfLine
  2052.    GP_SendCommand [getText $frst $lst ] 1000
  2053. }
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059. ################################################################################
  2060. #
  2061. #  Create floating menu
  2062. #
  2063. #
  2064. #
  2065.  
  2066. set GP_GraphMenu "gnuplotGraph"
  2067.  
  2068. set gp_grmen [list "menu  -n $GP_GraphMenu -p GnuplotMenuItem" ]
  2069. lappend gp_grmen "gnuplot" "(-" 
  2070.  
  2071. menu  -n $GP_GraphMenu -p GnuplotMenuItem   [ concat \
  2072.       "gnuplot" \
  2073.       ]
  2074.       
  2075.      
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081. ################################################################################
  2082. #
  2083. #  run load scripts from scripts menu
  2084. #
  2085. #
  2086. #
  2087.  
  2088. proc GP_ScriptMenuItems {menu item} {
  2089. global gp_sl gp_home gp_scriptItems gp_Path  gp_openItems
  2090.  
  2091.    set men [string tolower $menu]
  2092.    set ite [string tolower $item]
  2093.    
  2094.    if { "$item" == "Rebuild Menu" } {
  2095.         set cdir [pwd]
  2096.         set sl [expr [string length $gp_Path ] - 2] 
  2097.         cd [string range $gp_Path 0 $sl ]
  2098.      GP_RebuildScriptMenu
  2099.      cd "$cdir"
  2100.      return 0
  2101.    }
  2102.    
  2103.    foreach it $gp_scriptItems {
  2104.         if { [string match "cd \'*$men:\'; load \'*$men:$ite\'" [string tolower $it] ] } {
  2105.           GP_SendCommand "$it" 110
  2106.           return 0
  2107.      }      
  2108.     }
  2109.  
  2110.    #set men [string tolower [string range $menu 5 [string length $menu] ] ]
  2111.    
  2112.    # filter out the "• edit "  from the selected $menu $item
  2113.    set ite [string tolower [string range $item 7 [string length $item] ] ]
  2114.  
  2115.    foreach it $gp_openItems {
  2116.         if { [string match "*$men:$ite" [string tolower $it] ] } {
  2117.           edit "$it" 
  2118.           changeMode GPLT 
  2119.           return 0
  2120.      }      
  2121.     }
  2122. }
  2123.  
  2124.  
  2125.  
  2126. ################################################################################
  2127. #
  2128. #  Create a floating gnuplot graph button (Alpha 6.2 or higher)
  2129. #
  2130. #
  2131. #
  2132. proc GP_GraphButton {} {    
  2133. global gp_floatmenu GP_GraphMenu GPLTmodeVars gp_sl gp_Path gp_GEOM gp_FLTGEOM
  2134.  
  2135.   
  2136. #    if {[llength $gp_FLTGEOM] != 2 } {    
  2137.         if {[llength $gp_GEOM] == 4 } {
  2138.               set l [ expr [lindex $gp_GEOM 0] + 5 + [lindex $gp_GEOM 2] ]
  2139.               set t [ expr [lindex $gp_GEOM 1] - 20 ]
  2140.                set gp_FLTGEOM [list $l $t ] 
  2141.          } else {
  2142.              set l 20
  2143.              set t 20
  2144.          }
  2145. #    }  else {
  2146. #          set l  [lindex $gp_FLTGEOM 0]  
  2147. #          set t  [lindex $gp_FLTGEOM 1]  
  2148. #    }
  2149.     
  2150.      if {$GPLTmodeVars(GraphButton) } { 
  2151.         if { (![info exists  gp_floatmenu] )} {
  2152.              set gp_floatmenu [float -m $GP_GraphMenu -n "" -M -1 -z GPLT -l $l -t $t ]
  2153.         } 
  2154.      
  2155.     } 
  2156.     
  2157. }
  2158.  
  2159.  
  2160.  
  2161. ################################################################################
  2162. #
  2163. #  Generate the script menu 
  2164. #      
  2165. #
  2166.  
  2167. proc GP_ScriptList { sdir men } {
  2168. global gp_scriptItems  gp_openItems
  2169.    
  2170.     if {"$men" == "Scripts" } {
  2171.         set sl [list "\(Rebuild Menu"]
  2172.     } else {
  2173.         set sl [list]
  2174.     }
  2175.     
  2176.     # get the list of text files in $sdir
  2177.     set gp_fl [ glob -nocomplain -t TEXT "$sdir"] 
  2178.     set mdir [string range "$sdir" 0 [expr [string length "$sdir"] - 2 ] ] 
  2179.     set rdir [string range "$mdir" 0 [expr [string length "$mdir"] -1 ] ]
  2180.     foreach f $gp_fl {
  2181.       set mitem [string range $f [expr 1 + [string last ":" "$f" ] ] [ string length "$f" ] ]
  2182.       #append mitem "&"
  2183.       if { $mitem != "" } { 
  2184.           lappend sl "<E<S$mitem" 
  2185.           lappend sl "<S<I• edit $mitem" 
  2186.           lappend sl "<S<B• edit $mitem" 
  2187.           lappend sl "<S<U• edit $mitem" 
  2188.           lappend sl "<S<O• edit $mitem" 
  2189.         lappend gp_scriptItems "cd \'$rdir\'; load \'$f\'"
  2190.         lappend gp_openItems "$f"
  2191.       }
  2192.     }
  2193.     
  2194.     # get the list of aliased directories in $sdir and
  2195.     # perform this operation again on subdirectories
  2196.     set dlist [ glob   -t fdrp -nocomplain "$sdir"]
  2197.     foreach d $dlist {
  2198.        set dn [string range $d [expr [string last ":" "$d" ] +1 ] [string length $d]   ]
  2199.        #set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  2200.        set sl [concat "$sl"  [concat " \{menu -m -n" "\"$dn\"" -p GP_ScriptMenuItems  " \{  "  ] ]
  2201.        set dnam $d
  2202.        append dnam "*" 
  2203.        #set gp_ssl [ GP_ScriptList "$dnam" $dn ]
  2204.        set gp_ssl [list "(ALIASED FOLDERS NOT WORKING YET"]
  2205.        set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  2206.     }
  2207.     
  2208.     # get the list of directories in $sdir and
  2209.     # perform this operation again on subdirectories
  2210.     set dlist [ glob -nocomplain  "$sdir:"]
  2211.     foreach d $dlist {
  2212.        set dn [string range $d 0 [expr [string last ":" "$d" ] - 1 ]  ]
  2213.        set dn [string range $dn [expr 1 + [string last ":" "$dn" ] ] [ string length "$dn" ] ]
  2214.        set sl [concat "$sl"  [concat " \{menu -m -n" "\"$dn\"" -p GP_ScriptMenuItems  " \{  "  ] ]
  2215.        set dnam $d
  2216.        append dnam "*" 
  2217.        set gp_ssl [ GP_ScriptList "$dnam" $dn ]
  2218.        set sl [ concat "$sl "  $gp_ssl " \}  \} " ]
  2219.     }
  2220.     
  2221.     return  $sl 
  2222. }
  2223.    
  2224.  
  2225. ################################################################################
  2226. #
  2227. #  Kill a floating gnuplot menu (Alpha 6.2 or higher)
  2228. #
  2229. #
  2230. #
  2231. proc GP_KillGraphButton {} {    
  2232. global gp_floatmenu GnuplotMenu GPLTmodeVars 
  2233.  
  2234. if { [info exists  gp_floatmenu] }  { #
  2235.      catch {unfloat $gp_floatmenu } ans
  2236.      unset gp_floatmenu
  2237.     }
  2238. }
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244. ################################################################################
  2245. #
  2246. #  Load a script into gnuplot 
  2247. #      
  2248. #
  2249.  
  2250. proc GP_LoadScript {} {
  2251.     global gp_cwd
  2252.     catch { cd "$gp_cwd" } hmm
  2253.     set GPLTFile [ getfile "Choose a script to load:" ]
  2254.    if { $GPLTFile != "" } {    
  2255.        GP_SendCommand  "load \'$GPLTFile\'" 120
  2256.     }
  2257. }
  2258.  
  2259.  
  2260.  
  2261. ################################################################################
  2262. #
  2263. #  Tell gnuplot to save settings...
  2264. #
  2265. #
  2266. #
  2267.  
  2268. proc GP_SaveSettings { what } {
  2269. global  GPLTmodeVars gp_cwd gp_TYPE gp_CREA
  2270.  
  2271.    catch { cd "$gp_cwd" } hmm
  2272.    set tCREA $gp_CREA
  2273.    set tTYPE $gp_TYPE
  2274.    set gp_CREA {ALFA}
  2275.    set gp_TYPE {TEXT}
  2276.     set where [ putfile "Save current gnuplot settings" \
  2277.       [format "gnuplot%src.gp" [string toupper $what ] ] ]
  2278.     if { $where != "" } { 
  2279.       GP_SendCommand "save $what \'$where\'" 130
  2280.     }
  2281.     set gp_CREA  $tCREA
  2282.     set gp_TYPE  $tTYPE
  2283. }
  2284.  
  2285.  
  2286.  
  2287. ################################################################################
  2288. #
  2289. #  Tell gnuplot where the current dir is...
  2290. #
  2291. #
  2292. #
  2293.  
  2294. proc GP_SetCWD {} {
  2295.     set gp_cwd [ get_directory -p "Select gnuplot working folder"]
  2296.     if { $gp_cwd != "" } {
  2297.         GP_SendCommand "cd \'$gp_cwd\'" 140
  2298.     }
  2299. }
  2300.  
  2301.  
  2302.  
  2303. ################################################################################
  2304. #
  2305. #  Tell gnuplot to change the point size
  2306. #
  2307. #
  2308. #
  2309.  
  2310. proc GP_SetPTSZ {} {
  2311.     GP_SendCommand " set pointsize [ getline "Enter point size" 1 ] " 150
  2312. }
  2313.  
  2314. ################################################################################
  2315. #
  2316. #  Choose a file to plot and write "plot 'filename'" on command line
  2317. #
  2318. #
  2319. #
  2320.  
  2321. proc GP_ChoosePlotFile { } {
  2322.     global gp_Console gp_cwd
  2323.     catch { cd "$gp_cwd" } hmm
  2324.     set plotfile [ getPathName "Choose a file to plot" 1 ] 
  2325.    if { $plotfile != "" } {
  2326.         insertText -w "$gp_Console" "plot \'$plotfile\' "
  2327.     }
  2328. }
  2329.  
  2330.  
  2331. ################################################################################
  2332. #
  2333. #  Setup menu flags, etc ... assuming gnuplot is off
  2334. #
  2335. #
  2336. #
  2337. proc GP_OffSet {} {
  2338. global GnuplotMenu gp_CreatorList
  2339.     
  2340.     enableMenuItem gnuplotOptions "clearHistory" off                 
  2341.     enableMenuItem $GnuplotMenu "quit gnuplot" off                 
  2342.     enableMenuItem $GnuplotMenu "graph" off                 
  2343.     enableMenuItem $GnuplotMenu "history" off                 
  2344.     enableMenuItem $GnuplotMenu "saveSettings" off  
  2345.     enableMenuItem gnuplotOptions "setPointSize..." off  
  2346.     enableMenuItem $GnuplotMenu "setWorkingFolder..." off
  2347.     enableMenuItem $GnuplotMenu "choosePlotFile..."     off
  2348.     
  2349.     if {[llength $gp_CreatorList] == 0} {
  2350.         enableMenuItem  setOutputCreator "Select..." off
  2351.         enableMenuItem  setOutputCreator "Delete..." off
  2352.     }
  2353.     
  2354. }
  2355.  
  2356. ################################################################################
  2357. #
  2358. #  TEMPORARY JUNK
  2359. #
  2360. #
  2361. #
  2362. set gp_cwd "???"
  2363.  
  2364. proc aevt { hmm } { #dummy procedure too fool 68k into semi-working w/eventHandler....
  2365.    if { $hmm == "'GP_A'()" } {
  2366.         GP_Activate
  2367.    } elseif {$hmm=="'GP_C'()" } {
  2368.        GP_Results "gnuplot> "
  2369.       
  2370.    }    
  2371. }
  2372.      
  2373.  
  2374. ################################################################################
  2375. #
  2376. #  Things to do in order to properly setup gnuplot mode menu
  2377. #
  2378. #
  2379. #
  2380. set gp_modflag 0
  2381. GP_OffSet
  2382.  
  2383.  
  2384. ################################################################################
  2385. #
  2386. #  A simple user message
  2387. #
  2388. #
  2389. #
  2390. proc GP_Readme {} {    
  2391.   set wname "message"
  2392.   new -n $wname -m GPLT
  2393.   GP_uFD
  2394.  
  2395.   insertText { 
  2396. #
  2397.    gnuplotMode.tcl Version 1.82
  2398.  
  2399. #   NEWSTUFF:
  2400. #   ---------
  2401.  
  2402.    This version has a simple floating menu with a button that lists
  2403.    all texts files in the scripts directory of gnuplot home dir.
  2404.    To run a script, just select it from the scripts menu.  To edit
  2405.    a script in Alpha, select a script menu item while holding down a 
  2406.    modifier key (shift, option, command, OR ctrl).
  2407.  
  2408.  
  2409.    Modify some of the GPLT mode behaviour by choosing the menu item:
  2410.  
  2411. #     Config:Current Mode:Flags...
  2412.  
  2413.  
  2414.    To edit keyword coloring choose the configure menu item:
  2415.  
  2416. #     Config:Current Mode:Edit Prefs
  2417.  
  2418.  
  2419.  
  2420. #   GNUPLOT works best with Alpha 6.2 or later
  2421. #   ------------------------------------------
  2422.  
  2423. #   FOR 68K USERS ONLY
  2424. #   ------------------
  2425.  
  2426.    Recent versions of Alpha (<6.2) do not have a fully working      
  2427.    eventHandler procedure.  Thus, you might notice strange behavior  
  2428.    in the gnuplot console.  The symptoms of the problem are that     
  2429.    a new gnuplot prompt may not be displayed on the screen after     
  2430.    pressing a carriage return;  or, longer messages may be garbled. 
  2431.   
  2432.    Try the following: 
  2433.  
  2434. #      set term post
  2435. #      plot sin(x)
  2436.  
  2437.    If you see pages of postscript output, then the eventHandler is 
  2438.    apparently working.
  2439.  
  2440.    If not, then to make effective use of the console you may need   
  2441.    to open the Config:Current Mode:flags... menu in Alpha (when in  
  2442.    
  2443.    Keep an eye out at ftp://www.cs.umd.edu/pub/faculty/keleher/Alpha
  2444.    for the latest versions of Alpha which will eventually solve      
  2445.    this problem.
  2446.  
  2447. #   jeff@wave.nrl.navy.mil 
  2448. }    
  2449.    
  2450.   setWinInfo -w $wname dirty 0
  2451.      
  2452. }
  2453.  
  2454.  
  2455. #############################################################################
  2456. #
  2457. #  change behavior of editCurrentModePrefs
  2458. #
  2459.  
  2460. proc GP_editCurrentModePrefs { } {
  2461.        global mode GPLTmodeVars gp_modflag PREFS gp_HistGEOM gp_GEOM
  2462.        global GnuplotMenu  gp_Graph gp_Console  gp_Hist 
  2463.        global PREFS HOME 
  2464.  
  2465.        set wins  [winNames]
  2466.        set jjwinThere [lsearch $wins "GPLTPrefs.tcl"]
  2467.        set searchString1 {[\n\r]###BGK[\n\r](.*)[\n\r]###EGK[\n\r]}
  2468.       
  2469.        if { $jjwinThere >= 0} {
  2470.            set ss [searchInFile "$PREFS:GPLTPrefs.tcl"  "$searchString1" ]
  2471.            if { $ss == "" } {
  2472.                    goto [maxPos]
  2473.                if {$ss == ""} {
  2474.                    set ss [searchInFile "$HOME:tcl:usercode:gnuplotMode.tcl" \
  2475.                      "$searchString1" ]
  2476.                 }
  2477.                if {$ss == ""} {
  2478.                    set ss [searchInFile "$HOME:tcl:systemcode:gnuplotMode.tcl" \
  2479.                      "$searchString1" ]
  2480.                 }
  2481.                if {$ss == ""} {                                                   
  2482.                    set ss [searchInFile "$PREFS:gnuplotMode.tcl" "$searchString1" ]
  2483.                 } 
  2484.                if {$ss == ""} {                                                   
  2485.                    set ss [searchInFile "$HOME:tcl:Modes:gnuplotMode.tcl" \
  2486.                      "$searchString1" ]
  2487.                 } 
  2488.                if {$ss == ""} {                                                   
  2489.                    alertnote "Sorry, you'll have to edit gnuplotMode.tcl on your own."
  2490.                 } else {
  2491.                   insertText  -w "GPLTPrefs.tcl" "\n\n$ss\n\n"
  2492.                   goto 1
  2493.                }
  2494.            }
  2495.       }
  2496. }
  2497.  
  2498.  
  2499. set gp_fm_first 1
  2500.  
  2501.  
  2502.  
  2503. #############################################################################
  2504. #
  2505. #  Called from menu to handle dialogs in the server app
  2506. #  
  2507. #
  2508. proc GP_Dialog { ans } {
  2509. global  GnuplotSig
  2510.     switchTo  \'$GnuplotSig\'
  2511.     AEBuild -t 3600 -r 'GPSE' GPLT "DIAG" ---- $ans
  2512.     switchTo 'ALFA'
  2513. }
  2514.